<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

class logs_html {
    function filter( $formValues, $lists){
        mosCommonHTML::loadCalendar();
        ?>
        <form method="post" action="index2.php" name="adminForm">
        <table width="90%">
        <tr>
            <td>
                <label for="company">Company:</label>
            </td>
            <td>
                <?php echo $lists['companies']; ?>
            </td>
            <td>
                <input type="checkbox" name="raw"  value="1" <?php if ( $formValues['raw'] ) echo 'checked'; ?> />
            </td>
            <td>
                <label for="raw">Download Raw:</label>
            </td>
            <td>
                <label for="from">Date From:</label>
            </td>
            <td>
                <input type="text" name="from" id="from" size="25" maxlength="19" value="<?php echo $formValues['from']; ?>" />
                <input name="reset" type="reset" class="button" onclick="return showCalendar('from', 'y-mm-dd');" value="..." />
            </td>
            <td>
                <input type="checkbox" name="emailit"  value="1" <?php if ( $formValues['emailit'] ) echo 'checked'; ?> />
            </td>
            <td>
                <label for="emailit">Send the report by email</label>
            </td>
        </tr>
        <tr>
            <td>
                <label for="report">Report:</label>
            </td>
            <td>
                <?php echo $lists['reports']; ?>
            </td>
            <td>
                <input type="checkbox" name="adminfields" value="1" <?php if ( $formValues['adminfields'] ) echo 'checked'; ?> />
            </td>
            <td>
                <label for="adminfields">Bill Amount:</label>
            </td>
            <td>
                <label for="to">Date To:</label>
            </td>
            <td>
                <input type="text" name="to" id="to" size="25" maxlength="19" value="<?php echo $formValues['to']; ?>" />
                <input name="reset" type="reset" class="button" onclick="return showCalendar('to', 'y-mm-dd');" value="..." />
            </td>
            <td>
                <input type="radio" name="emailto" value="author" <?php if ( $formValues['emailto'] == 'author') echo 'checked'; ?> <?php if( $formValues['company'] < 1) echo "disabled"; ?>/>
                Advertiser
            </td>
            <td>
                <input type="radio" name="emailto"  value="specificemail" <?php if ( $formValues['emailto'] == 'specificemail') echo 'checked'; ?>/>
                <input type="text" name="email" id="email" size="25" value="<?php echo $formValues['email']; ?>" />
            </td>
        </tr>
        </table>
        <input type="hidden" name="option" value="com_logs" />
        <input type="hidden" name="task" value="" />
        </form>
        <script language="JavaScript" type="text/javascript">
            function submitbutton(pressbutton){
                var form = document.adminForm;
                if (pressbutton == 'reports') {
                    if (form.from.value == ""){
                        alert( "You must select a date from." );
                    } else if (form.to.value == ""){ 
                        alert( "You must select a date to." );
                    } else if (form.emailit.checked  && form.emailto[1].checked && form.email.value == "" ){ 
                        alert( "If you want to mail the report You must write a email address." );
                    } else {
                        submitform( pressbutton );
                    }
                }
            }
            
            function switchEmail(){
                var form = document.adminForm;
                if (form.company.value < 1){
                    form.emailto[0].disabled = true;
                }else{
                    form.emailto[0].disabled = false;
                }
            }
        </script>
    <?
    }

    function filter_purge( ){
        mosCommonHTML::loadCalendar();
        ?>
        <form method="post" action="index2.php" name="adminForm">
        <table width="90%">
        <tr>
            <td>
                <label for="from">Date From:</label>
            </td>
            <td>
                <input type="text" name="from" id="from" size="25" maxlength="19" value="" />
                <input name="reset" type="reset" class="button" onclick="return showCalendar('from', 'y-mm-dd');" value="..." />
            </td>
            <td>
                <label for="to">Date To:</label>
            </td>
            <td>
                <input type="text" name="to" id="to" size="25" maxlength="19" value="" />
                <input name="reset" type="reset" class="button" onclick="return showCalendar('to', 'y-mm-dd');" value="..." />
            </td>

        </tr>
        </table>
        <input type="hidden" name="option" value="com_logs" />
        <input type="hidden" name="task" value="" />
        </form>
        <script language="JavaScript" type="text/javascript">
            function submitbutton(pressbutton){
                var form = document.adminForm;
                if (pressbutton == 'purge') {
                    if (form.from.value == ""){
                        alert( "You must select a date from." );
                    } else if (form.to.value == ""){ 
                        alert( "You must select a date to." );
                    } else {
                        submitform( pressbutton );
                    }
                }
            }
            
            function switchEmail(){
                var form = document.adminForm;
                if (form.company.value < 1){
                    form.emailto[0].disabled = true;
                }else{
                    form.emailto[0].disabled = false;
                }
            }
        </script>
    <?
    }

    function reports($rows, $formValues,$extraCBFields){
    ?>
        <table width="100%" align="left">
            <tr>
                <?php if ($formValues['report'] > 1): ?>
                <th>Reference</th>
                <th>Date</th>
                <?php endif; ?>
                <th>Company</th>
                <th>Document</th>
                <?php if ($formValues['adminfields']): ?>
                <th>Bill</th>
                <?php endif; ?>
                <?php if ($formValues['report'] > 1): ?>
                <th>User</th>
                <th>Question 1</th>
                <th>Answer 1</th>
                <th>Question 2</th>
                <th>Answer 2</th>
                <th>Question 3</th>
                <th>Answer 3</th>
                <?php endif; ?>
                <?php if ($formValues['report'] == 1): ?>
                <th>Hits</th>
                <?php endif; ?>
                <?php if ($formValues['report'] == 3): ?>
                <th><?php echo @$extraCBFields[1]['title']; ?></th>
                <th><?php echo @$extraCBFields[2]['title']; ?></th>
                <th><?php echo @$extraCBFields[3]['title']; ?></th>
                <th><?php echo @$extraCBFields[4]['title']; ?></th>
                <th><?php echo @$extraCBFields[5]['title']; ?></th>
                <th><?php echo @$extraCBFields[6]['title']; ?></th>
                <th><?php echo @$extraCBFields[7]['title']; ?></th>
                <th><?php echo @$extraCBFields[8]['title']; ?></th>
                <th><?php echo @$extraCBFields[9]['title']; ?></th>
                <?php endif; ?>
            </tr>
            <?php foreach((array)$rows as $key => $row): ?>
            <tr>
                <?php 
                    if ($formValues['report'] > 1){
                        echo "<td>{$row->id}</td>";
                        echo "<td>{$row->date}</td>";
                    }
                    echo "<td>{$row->name}</td>";
                    echo "<td>{$row->dmname}</td>";
                    if ($formValues['adminfields']){
                        echo "<td>{$row->ammount}</td>";
                    }
                        if ($formValues['report'] > 1 ){
                        echo "<td>{$row->nameofuser}</td>";
                            echo "<td>{$row->question1}</td>";
                            echo "<td>{$row->answer1}</td>";
                            echo "<td>{$row->question2}</td>";
                            echo "<td>{$row->answer2}</td>";
                            echo "<td>{$row->question3}</td>";
                            echo "<td>{$row->answer3}</td>";
                    }
                    if ($formValues['report'] == 1 ){
                        echo "<td>{$row->hits}</td>";
                    }
                    if ($formValues['report'] == 3 ){
                        echo "<td>{$row->extra1}</td>";
                        echo "<td>{$row->extra2}</td>";
                        echo "<td>{$row->extra3}</td>";
                        echo "<td>{$row->extra4}</td>";
                        echo "<td>{$row->extra5}</td>";
                        echo "<td>{$row->extra6}</td>";
                        echo "<td>{$row->extra7}</td>";
                        echo "<td>{$row->extra8}</td>";
                        echo "<td>{$row->extra9}</td>";
                    }
                ?>
            </tr>
            <?php endforeach; ?>
        </table>
        <?php
    }
}
?>